#include "base.h"
#include "text.h"

Text::Text()
{
	//sets the default values
	this->m_bVisible = true;
	this->m_stText = "";
	this->m_position.SetXYZ(0.0f, 0.0f, 0.0f);
	this->m_Size.SetXYZ(1.0f, 1.0f, 1.0f);
	this->m_Colour.SetRGB(1.0f, 1.0f, 1.0f);
}

Text::Text(string words)
{
	//sets the default values
	this->m_bVisible = true;
	this->m_stText = words;
	this->m_position.SetXYZ(0.0f, 0.0f, 0.0f);
	this->m_Size.SetXYZ(1.0f, 1.0f, 1.0f);
	this->m_Colour.SetRGB(1.0f, 1.0f, 1.0f);
}

Text::~Text()
{
}

void Text::Draw()
{
	glPushMatrix();

	//set the colour
	glColor4f(this->m_Colour.Red(), this->m_Colour.Green(), this->m_Colour.Blue(), 0.0);

	//set the position
	glRasterPos2f(this->m_position.GetX(), this->m_position.GetY());

	//set the size
	glScalef(this->m_Size.GetX(), this->m_Size.GetY(), this->m_Size.GetZ());

	//get the string for output
	const char* s = this->m_stText.c_str();

	//work through the string character by character
	if (s && strlen(s)) 
	{
		//while there are still characters
		while (*s) 
		{
			//draw the character
			glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *s);
			//move to the next character
			s++;
		}
	}

	glPopMatrix();
}

bool Text::Visible()
{
	//returns visibility
	return this->m_bVisible;
}

void Text::SetVisible(bool state)
{
	//sets the state of the visibility
	this->m_bVisible = state;
}

void Text::SetPosition(float X, float Y)
{
	//sets the position of the text
	this->m_position.SetXYZ(X, Y, 1.0f);
}

void Text::SetMagnification(float mag)
{
	this->m_Size.SetXYZ(mag, mag, 1.0f);
}

void Text::SetText(string words)
{
	//changes the text of the string
	this->m_stText = words;
}

void Text::SetColour(int Red, int Green, int Blue)
{
	//sets the colour - from 0 to 255
	this->m_Colour.SetRGB(Red, Green, Blue);
}

void Text::SetColour(float Red, float Green, float Blue)
{
	//sets the colour - from 0.0f to 1.0f
	this->m_Colour.SetRGB(Red, Green, Blue);
}